
#include "stdafx.h"
#include "doc_plugin_interface.h"
#include "wf_getent.h"
#include "pf_selection.h"
#include "pf_snapper.h"


WF_GetEnt::WF_GetEnt(PF_Container& container,
                                 PF_GraphicView& graphicView)
        :PF_ActionInterface("Get Entity", container, graphicView) {
    completed = false;
    mesage = tr("Select object:");
    en = NULL;
}


void WF_GetEnt::updateMouseButtonHints() {
    if (!completed)
        PF_DIALOGFACTORY->updateMouseWidget(mesage, tr("Cancel"));
    else
        PF_DIALOGFACTORY->updateMouseWidget("", "");
}


void WF_GetEnt::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::SelectCursor);
}

void WF_GetEnt::setMesage(QString msg){
    mesage = msg;
}

void WF_GetEnt::trigger() {
    if (en!=NULL) {
        PF_Selection s(*container, graphicView);
        s.selectSingle(en);
        completed = true;
        updateMouseButtonHints();
    } else {
        PF_DEBUG->print("QC_ActionGetEnt::trigger: Entity is NULL\n");
    }
}

void WF_GetEnt::mouseReleaseEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::RightButton) {
        init(getStatus()-1);
    } else {
        en = catchEntity(e);
        trigger();
    }
}

/**
 * Add selected entity from 'container' to the selection.
 */
Plugin_Entity *WF_GetEnt::getSelected() {
    Plugin_Entity *pe = new Plugin_Entity(en);
    return pe;
}

// EOF
